package hmvc4gwt.client.controller;

import hmvc4gwt.client.component.IComponent;
import hmvc4gwt.client.event.IHmvcEvent;
import hmvc4gwt.client.event.IHmvcEventListener;
import hmvc4gwt.client.model.IModel;
import hmvc4gwt.client.view.IView;

public abstract class AbstractController implements IController {
	
	private IComponent component;
	
	private boolean initialized = false;
	
	private boolean terminated = false;

	public IComponent addChildComponent(IController controller) {
		return component.addChildComponent(controller);
	}

	public IComponent addChildComponent(IController controller, IModel model) {		
		return component.addChildComponent(controller, model);
	}

	public IComponent addChildComponent(IController controller, IModel model, IView view) {
		return component.addChildComponent(controller, model, view);
	}

	public IComponent addChildComponent(IController controller, IView view) {
		return component.addChildComponent(controller, view);
	}

	public final void fireEvent(IHmvcEvent event, boolean up, boolean local,
			boolean down) {
		component.fireEvent(event, up, local, down);
	}

	/**
	 * fires the Event only to the local Controller
	 */
	public void fireEventLocal(IHmvcEvent event) {
		component.fireEvent(event, false, true, false);
	}
	
	public void fireEventDown(IHmvcEvent event) {
		component.fireEvent(event, false, false, true);
	}
	
	public void fireEventUp(IHmvcEvent event) {
		component.fireEvent(event, true, false, false);
	}

	public IComponent getComponent() {
		return component;
	}

	public IModel getModel() {
		return component.getModel();
	}

	public IView getView() {
		return component.getView();
	}
	
	public boolean isInitialized() {
		return initialized;
	}

	public boolean isTerminated() {
		return terminated;
	}

	public void post() {
	}

	public void pre() {
	}

	public void register(Class classOfEvent, IHmvcEventListener listener) {
		component.register(classOfEvent, listener);
	}

	public void setComponent(IComponent component) {
		this.component = component;
	}
	
	public void setInitialized(boolean initialized) {
		this.initialized = initialized;
	}
	
	public void setTerminated(boolean b) {
		component.setTerminated(b);
	}
}
